package org.coco.cloud.order.controller;

import org.coco.cloud.order.bean.Order;
import org.coco.cloud.order.proterties.OrderProterties;
import org.coco.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author fengleifl-hzgs
 * @Date 2025/1/19
 * @since
 */
//@RefreshScope
@RequestMapping("/api/order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

//    @Value("${order.timeout}")
//    String orderTimeOut;
//    @Value("${order.auto-confirm}")
//    String orderAutoConfirm;

    @Autowired
    OrderProterties orderProterties;

    @GetMapping("config")
    public String config() {
        return "order.timeout=" + orderProterties.getTimeOut() + ": order.auto-confirm=" + orderProterties.getAutoConfirm()
                + ": order.env=" + orderProterties.getEnv();
    }

    @GetMapping("create")
    public Order createOrder(@RequestParam(value = "productId") Long productId,
                             @RequestParam(value = "userId") Long userId) {
        Order order = orderService.createOrder(productId, userId);
        return order;
    }
}
